package cspro;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.naming.InitialContext;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class SUi extends JFrame{

	private JPanel mainPanel;
	private JPanel headPanel;
	private JPanel footPanel;
	private JTextArea showArea;
	private JTextField inputTxt;
	private JLabel portLbl;
	private JLabel ipLbl;
	private JLabel nameLbl;
	private JTextField portTxt;
	private JTextField ipTxt;
	private JTextField nameTxt;
	private JButton submitBtn;
	private JButton nameBtn;
	private JButton loginBtn;
	private Socket clientSocket = null;
	private DataOutputStream dos = null;
	private DataInputStream dis = null;
	private boolean bConnect = false;
	private String name = "";
	
	public static void main(String args[]){
		SUi ui = new SUi();
	}
	
	public SUi()
	{
		init();
	}
	private void init()
	{
		//main panel Begin
		mainPanel = new JPanel();
		showArea = new JTextArea(15, 80);
		showArea.setEditable(false);
		mainPanel.add(showArea);
		getContentPane().add(mainPanel, BorderLayout.CENTER);
		//main panel End
		
	
		
		//foot panel Begin
		footPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		inputTxt = new JTextField(70);
		submitBtn = new JButton("start Server");
	//	footPanel.add(inputTxt);
		footPanel.add(submitBtn);
		submitBtn.addActionListener(new ButtonClickAction());
		//submitBtn.setEnabled(false);
		getContentPane().add(footPanel, BorderLayout.SOUTH);
		//foot panel End
//		addWindowListener(new WindowAdapter()
//		{
//			public void windowClosing(WindowEvent e)
//			{
//				disConnect();
//				System.exit(0);
//			}
//		});
		this.setSize(300, 300);
		setLocation(100, 100);
		pack();
		setVisible(true);
	}
	/**
	 * login button / submit button action listener
	 * 
	 * @author hx0272
	 * 
	 */
	class ButtonClickAction implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			new Thread(new Runnable() {
				public void run() {
					System.out.println("start server");
					showArea.setText("start Server...");
					Server.listenConnect();
					showArea.append("\n server may be Started!");
				}
			}).start();
			
			
		}
	}
	

}
